package controllers

import (
	"gin_cli/pkg/e"
	"gin_cli/pkg/util"
	"net/http"

	"github.com/astaxie/beego/validation"
	"github.com/gin-gonic/gin"
)

type Auth struct {
}

func (this *Auth) GetToken(c *gin.Context) {
	valid := validation.Validation{}
	body := make(map[string]string)
	c.BindJSON(&body)
	username := body["username"]
	password := body["password"]
	valid.MinSize(username, 6, "username").Message("最小长度为6")
	valid.MinSize(password, 6, "password").Message("最小长度为6")
	if result, err := util.Validate(valid); err != nil {
		c.JSON(
			http.StatusBadRequest,
			e.GetResponse(e.INVALID_PARAMS, result),
		)
		c.Abort()
		return
	}
	// token, _ := util.GenerateToken(1, username, password)
	c.JSON(
		http.StatusOK,
		e.GetResponse(e.SUCCESS, "token"),
	)
}
